interface Assert {
  ok: (v: any, error?: string) => void | Error
  deepEqual: (v1: any, v2: any, error?: string) => void | Error
  equal: (v1: any, v2: any, error?: string) => void | Error
  [name: string]: (...p: any[]) => any
}

/** 验证函数 */
interface Func { (t: Assert, ...p: any[]): any }

/** 队列容器，搜集并保存测试函数 */
interface Container {
  [name: string]: { name: string, func: Func }[]
}

const container: Container = {
  before: [],
  default: [],
  after: [],
  skip: [],
};

/**
* 
* @param name 测试名
* @param func 测试方法
*/
function test(name: string, func: Func) {
  container.default.push({ name, func });
}

/**
* 跳过执行
* @param name 测试名
* @param func 测试方法
*/
test.skip = function (name: string, func: Func) {
  container.skip.push({ name, func });
}

/**
* 前置钩子
* @param name 测试名
* @param func 测试方法
*/
test.before = function (name: string, func: Func) {
  container.before.push({ name, func });
}

/**
* 后置钩子
* @param name 测试名
* @param func 测试方法
*/
test.after = function (name: string, func: Func) {
  container.after.push({ name, func });
}

test.container = container;

export function sleep(time = 0) {
  return new Promise(resolve => setTimeout(resolve, time));
}

export default test;
